DAY42:Consecutive strings


Posted by birdbirdmurmur on 2023-08-24

題目連結

https://www.codewars.com/kata/56a5d994ac971f1ac500003e

解法

function longestConsec(strarr, k) {
    if (k <= 0 || strarr.length === 0) {
        return '';
    }

    let long = ''
    for (let i = 0; i < strarr.length - k + 1; i++) {
        const currString = strarr.slice(i, i + k).join('')
        if (currString.length > long.length) {
            long = currString
        }
    }
    return long
}

筆記


#javascript #Codewars







Related Posts

[JS] 陳述式(Statement)與表達式(Expression)

[JS] 陳述式(Statement)與表達式(Expression)

MTR04_1114

MTR04_1114

Simple Twitter 專案開發心得

Simple Twitter 專案開發心得


Comments